package experiment;

/**
 * Created by lenovo on 2016/4/12.
 */
public class ComplexNumberTest {
    public static void main(String[] args) {
        int pass=0,fail=0;
        ComplexNumber a = new ComplexNumber(2.2,3.3);
        ComplexNumber b = new ComplexNumber();
        b.setReal(-5.5);
        b.setImag(7.7);
        ComplexNumber c = new ComplexNumber();
        //getreal
        if(a.getReal()!=2.2){
            fail++;System.out.println(1);
        }else {
            pass++;
        }
        //grtimag
        if(a.getImag()!=3.3){
            fail++;System.out.println(2);
        }else {
            pass++;
        }
        //setreal
        if(b.getReal()!= -5.5){
            fail++;System.out.println(3);
        }else {
            pass++;
        }
        //setimag
        if(b.getImag()!=7.7){
            fail++;System.out.println(4);
        }else {
            pass++;
        }
        //初始化为0
        if(c.getReal()!=0||c.getImag()!=0){
            fail++;System.out.println(5);
        }else {
            pass++;
        }
        //toString 0
        if(c.toString()!="0"){
            fail++;System.out.println(6);
        }else {
            pass++;
        }
        //addComplex
        c=a.ComplexAdd(b);
        if(c.getReal()!= -3.3||c.getImag()!=11.0){
            fail++;System.out.println(c.toString()+"7");
        }else {
            pass++;
        }
        //add
        c=a.ComplexAdd(4.4);
        if(c.getReal()!=(2.2+4.4)||c.getImag()!=3.3){
            fail++;System.out.println(c.toString()+"8");
        }else {
            pass++;
        }
        //minusComplex
        c=a.ComplexMinus(b);
        if(c.getReal()!= 7.7||c.getImag()!= -4.4){
            fail++;System.out.println(c.toString()+"9");
        }else {
            pass++;
        }
        //minus
        c=a.ComplexMinus(9.9);
        if(c.getReal()!= -7.7||c.getImag()!= 3.3){
            fail++;System.out.println(c.toString()+"10");
        }else {
            pass++;
        }
        //multiComplex
        c=a.ComplexMulti(b);
        if(c.getReal()!=(2.2*-5.5-3.3*7.7)||c.getImag()!=(2.2*7.7+3.3*-5.5)){
            fail++;System.out.println(c.toString()+"11");
        }else {
            pass++;
        }
        //multi
        c=a.ComplexMulti(2.5);
        if(c.getReal()!= 5.5||c.getImag()!= 8.25){
            fail++;System.out.println(c.toString()+"12");
        }else {
            pass++;
        }
        //toString
        if(b.toString()!="-5.5 + 7.7i"){
            fail++;System.out.println(b.toString()+"13");
        }else {
            pass++;
        }
        a.setReal(-1.2);
        a.setImag(-3.4);
        if(a.toString()!="-1.2 - 3.4i"){
            fail++;System.out.println(a.toString()+"14");
        }else {
            pass++;
        }
        System.out.printf("pass%d,fail%d",pass,fail);
    }
}
